package config

import (
	"os"

	"gopkg.in/yaml.v3"
)

type Config struct {
	Server     serverConfig     `yaml:"server"`
	DataSource dataSourceConfig `yaml:"dataSource"`
	Redis      redisConfig      `yaml:"redis"`
}

type serverConfig struct {
	Addr string `yaml:"addr"`
}

type dataSourceConfig struct {
	Name string `yaml:"name"`
}

type redisConfig struct {
	Addr     string `yaml:"addr"`
	Password string `yaml:"password"`
	DB       int    `yaml:"db"`
}

func Load(path string) (Config, error) {
	var conf Config
	b, err := os.ReadFile(path)

	if err != nil {
		return conf, err
	}

	if err = yaml.Unmarshal(b, &conf); err != nil {
		return conf, err
	}

	return conf, nil
}
